// pages/solidList/solidList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    corpsList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.request({
      url: app.globalData.prefix + "/corpsAction/my.do",
      data: {
        openId: app.globalData.userInfo.openId
      },
      success: (res) => {
        let status = res.data.status
        if (status == "00") {
          let data = res.data.result
          let inCrops = data.inCorps
          if (inCrops) {
            wx.redirectTo({
              url: '../myArmy/myArmy'
            })
          } else {
            this.setData({
              corpsList: data.corpsList
            })
          }
        } else {
          wx.$showToast(res.data.errorMsg)
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  createArmy() {
    wx.navigateTo({
      url: '../createArmy/createArmy'
    })
  },
  applyCorps(res) {
    let corpsId = res.currentTarget.dataset['id']
    wx.request({
      url: app.globalData.prefix + "/corpsAction/apply.do",
      data: {
        openId: app.globalData.userInfo.openId,
        corpsId: corpsId
      },
      method: 'POST',
      success: (res) => {
        let status = res.data.status
        if (status == "00") {
          let data = res.data.result
          wx.showModal({
            content: data,
            showCancel: false,
            success: (res) => {
              if (res.confirm) {
                this.onShow()
              }
            }
          })
        } else {
          wx.$showToast(res.data.errorMsg)
        }
      }
    })
  }
})